/**
 * 店铺相关功能
 */
import { mysql } from 'src-ssr/db/connect';
import TableHelper from 'src-ssr/db/tableHelper';
import * as tools from 'src-ssr/util/common';
import logs from 'src-ssr/util/logs';
import { Sequelize, Op, QueryTypes } from 'sequelize';
import models, { sequelize } from 'src-ssr/db/sequelize';
import moment from 'moment';

import * as singleUtils from 'src-ssr/controller/common/singleOperate';

const menuName = 'shop';
const modelName = 'm_shops';
const modelLabel = '店铺信息';

// 取店铺信息
export const detail = async (req, res) => {
  const user = await tools.getLoginUser(req.get('Authorization').split(' ')[1]);
  const row = await models[modelName].findOne({
    where: {
      tenant_id: user.tid
    },
    raw: true
  });

  res.json(row);
};

/**
 * 创建店铺
 */
export const create = async (req, res) => {
  const ret = await singleUtils.createData(modelName, modelLabel, menuName, req, true, null);

  res.json(ret);
};

/**
 * 修改店铺
 */
export const update = async (req, res) => {
  const ret = await singleUtils.updateData(modelName, modelLabel, menuName, req, true, null);
  res.json(ret);
};
